import { Injectable } from '@angular/core';
import { ApolloQueryResult, FetchResult } from '@apollo/client/core';
import { Apollo, gql, QueryRef } from 'apollo-angular';
import { Observable } from 'rxjs';
import { ShareNamesServiceApi,
ShareNamesService_shareNamesResult,
ShareNamesService_shareNamesVariables,
ShareNamesService_myShareNamesListResult,
ShareNamesService_myShareNamesListVariables,
ShareNamesService_listResult,
ShareNamesService_listVariables,
ShareNamesService_totalCountResult,
ShareNamesService_searchResult,
ShareNamesService_searchVariables,
ShareNamesService_loadAllResult,
ShareNamesService_getByIdResult,
ShareNamesService_getByIdVariables,
ShareNamesService_setShareNamesResult,
ShareNamesService_setShareNamesVariables,
ShareNamesService_saveResult,
ShareNamesService_saveVariables,
ShareNamesService_removeByIdResult,
ShareNamesService_removeByIdVariables,
ShareNamesService_removeByIdListResult,
ShareNamesService_removeByIdListVariables,
ShareNamesResultInfo, ShareNamesPageInfo,
ShareNamesConnection,
ShareNamesPackage,
ShareNamesOrderBy,
ShareNamesMutationInfo,
ShareNamesStringFilter,
ShareNamesNumberFilter,
ShareNamesBooleanFilter,
shareNamesServiceQuery,
shareNamesServiceMutation,
ShareNamesServiceQueryOptions,
ShareNamesStore,
ShareNamesView,
ShareNamesInput,
ShareNamesFilter,
ShareNamesErrorBody} from '../model/share_names_service.model';

/************************************************************************
 * 共享资源
 */
@Injectable({
    providedIn: 'root'
})
export class ShareNamesService implements ShareNamesServiceApi {

        private shareNamesGql:string;
        private myShareNamesListGql:string;
        private listGql:string;
        private totalCountGql:string;
        private searchGql:string;
        private searchObjectRef: QueryRef<ShareNamesService_searchResult>;
        private loadAllGql:string;
        private getByIdGql:string;

    constructor(private apollo: Apollo) {
        this.shareNamesGql=`query nars_shareNamesService_shareNames($path: String!){${shareNamesServiceQuery.shareNamesService_shareNames}}`;
        this.myShareNamesListGql=`query nars_shareNamesService_myShareNamesList($first: Int!,$offset: Float!){${shareNamesServiceQuery.shareNamesService_myShareNamesList}}`;
        this.listGql=`query nars_shareNamesService_list($filter: ShareNamesFilter!,$orderBy: OrderBy){${shareNamesServiceQuery.shareNamesService_list}}`;
        this.totalCountGql=`query nars_shareNamesService_totalCount{${shareNamesServiceQuery.shareNamesService_totalCount}}`;
        this.searchGql=`query nars_shareNamesService_search($first: Int!,$offset: Float!,$filter: ShareNamesFilter!,$orderBy: OrderBy){${shareNamesServiceQuery.shareNamesService_search}}`;
        this.searchObjectRef = apollo.watchQuery<ShareNamesService_searchResult>({ query: gql`${this.searchGql}`, fetchPolicy:'cache-first' });
        this.loadAllGql=`query nars_shareNamesService_loadAll{${shareNamesServiceQuery.shareNamesService_loadAll}}`;
        this.getByIdGql=`query nars_shareNamesService_getById($id: String!){${shareNamesServiceQuery.shareNamesService_getById}}`;
    }
    /**
     * 获取共享文件
     */
    shareNames(variables: ShareNamesService_shareNamesVariables, options:ShareNamesServiceQueryOptions = { cachePolicy: 'no-cache', more: false }): Observable<ApolloQueryResult<ShareNamesService_shareNamesResult>> {
            return this.apollo.query({ query: gql`${this.shareNamesGql}`,variables ,fetchPolicy:options.cachePolicy});
    }
    /**
     * 获取当前共享的所有文件
     */
    myShareNamesList(variables: ShareNamesService_myShareNamesListVariables, options:ShareNamesServiceQueryOptions = { cachePolicy: 'no-cache', more: false }): Observable<ApolloQueryResult<ShareNamesService_myShareNamesListResult>> {
            return this.apollo.query({ query: gql`${this.myShareNamesListGql}`,variables ,fetchPolicy:options.cachePolicy});
    }
    /**
     * 分页查询
     */
    list(variables: ShareNamesService_listVariables, options:ShareNamesServiceQueryOptions = { cachePolicy: 'no-cache', more: false }): Observable<ApolloQueryResult<ShareNamesService_listResult>> {
            return this.apollo.query({ query: gql`${this.listGql}`,variables ,fetchPolicy:options.cachePolicy});
    }
    /**
     * 统计库中所有对象的数据量
     */
    totalCount(options:ShareNamesServiceQueryOptions = { cachePolicy: 'no-cache', more: false }): Observable<ApolloQueryResult<ShareNamesService_totalCountResult>> {
            return this.apollo.query({ query: gql`${this.totalCountGql}`,fetchPolicy:options.cachePolicy});
    }
    /**
     * 游标查询
     */
    search(variables: ShareNamesService_searchVariables, options:ShareNamesServiceQueryOptions = { cachePolicy: 'cache-first', more: false }): Observable<ApolloQueryResult<ShareNamesService_searchResult>> {
        this.searchObjectRef.setVariables(variables);
        if(options.more){
            this.searchObjectRef.fetchMore({variables});
        }
        return this.searchObjectRef.valueChanges;
    }
    /**
     * 获取库中所有数据，数据量大时请谨慎使用
     */
    loadAll(options:ShareNamesServiceQueryOptions = { cachePolicy: 'cache-first', more: false }): Observable<ApolloQueryResult<ShareNamesService_loadAllResult>> {
            return this.apollo.query({ query: gql`${this.loadAllGql}`,fetchPolicy:options.cachePolicy});
    }
    /**
     * 获取一个对象
     */
    getById(variables: ShareNamesService_getByIdVariables, options:ShareNamesServiceQueryOptions = { cachePolicy: 'cache-first', more: false }): Observable<ApolloQueryResult<ShareNamesService_getByIdResult>> {
            return this.apollo.query({ query: gql`${this.getByIdGql}`,variables ,fetchPolicy:options.cachePolicy});
    }
    /**
     * 共享文件
     */
    setShareNames(variables: ShareNamesService_setShareNamesVariables): Observable<FetchResult<ShareNamesService_setShareNamesResult>>{
        return this.apollo.mutate({mutation: gql`mutation nars_shareNamesService_setShareNames($path: String!,$time: Float!,$extractCode: Boolean!,$disclosure: Boolean!){${shareNamesServiceMutation.shareNamesService_setShareNames}}`, variables,fetchPolicy:'no-cache'});
    }
    /**
     * 保存对象
     */
    save(variables: ShareNamesService_saveVariables): Observable<FetchResult<ShareNamesService_saveResult>>{
        return this.apollo.mutate({mutation: gql`mutation nars_shareNamesService_save($entity: ShareNamesInput!){${shareNamesServiceMutation.shareNamesService_save}}`, variables,fetchPolicy:'no-cache'});
    }
    /**
     * 删除一个对象
     */
    removeById(variables: ShareNamesService_removeByIdVariables): Observable<FetchResult<ShareNamesService_removeByIdResult>>{
        return this.apollo.mutate({mutation: gql`mutation nars_shareNamesService_removeById($id: String!){${shareNamesServiceMutation.shareNamesService_removeById}}`, variables,fetchPolicy:'no-cache'});
    }
    /**
     * 删除一批对象
     */
    removeByIdList(variables: ShareNamesService_removeByIdListVariables): Observable<FetchResult<ShareNamesService_removeByIdListResult>>{
        return this.apollo.mutate({mutation: gql`mutation nars_shareNamesService_removeByIdList($ids: [String]!){${shareNamesServiceMutation.shareNamesService_removeByIdList}}`, variables,fetchPolicy:'no-cache'});
    }









}
